package gui

import (
	"os"
	"path/filepath"

	"strings"

	"github.com/andlabs/ui"
)

var chanSrc = make(chan map[string]bool)
var chanTrg = make(chan map[string]bool)

//遍历目录
func walk(root string, console *ui.MultilineEntry,   chan_path chan map[string]bool) {
	set_path := map[string]bool{}

	err := filepath.Walk(root, func(path string, fi os.FileInfo, err error) error {
		if err != nil {
			console.Append(err.Error() + "\n")
			return err
		}

		if !fi.IsDir() {
			return nil
		}

		set_path[deal_path(path, root)] = true
		return nil
	})
	check(err)
	chan_path <- set_path
}

func deal_path(path, root string) string {
	return path[strings.Index(path, root)+len(root):]
}

//map是否包含键k
func contains(dict map[string]bool, k string) bool {
	if _, ok := dict[k]; ok {
		return true
	} else {
		return false
	}
}

func compare(src, trg map[string]bool, console *ui.MultilineEntry, entry1 *ui.MultilineEntry, entry2 *ui.MultilineEntry, ) {
	console.Append("=========== common path ================\n")
	// 删除公共的key
	for k := range src {
		if contains(trg, k) {
			console.Append(k + "\n")
			delete(trg, k)
			delete(src, k)
		}
	}
	//剩下不同key
	for k := range src {
		entry1.Append(k + "\n")
	}
	for k := range trg {
		entry2.Append(k + "\n")
	}

}


func printEnv(console *ui.MultilineEntry)  {

}
